<?php
include('../resource/db/db.php');
$pageTitle = "管理卡组";
$currentPage = "manage-cards";
if (!isset($_COOKIE['role']) || $_COOKIE['role'] != 'admin') {
    header("Location: ../main/login.php");
    exit();
}

$sql = "SELECT * FROM cards WHERE is_deleted=FALSE";
$result = $conn->query($sql);
?>

<!DOCTYPE html>
<html>
<head>
    <title>管理卡片</title>
    <link rel="stylesheet" href="../resource/css/styles.css">
</head>
<body>
    <?php include('../resource/navbar.php'); ?>
    <div class="container">
        <h2>管理卡片</h2>
        <ul class="list-group">
            <?php
            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "<li class='list-group-item'>";
                    echo "Set ID: " . $row['set_id'] . " | ";
                    echo "Card ID: " . $row['card_id'] . " | ";
                    echo "Title: " . $row['title'] . " ";
                    echo "<a href='edit-card.php?card_id=" . $row['card_id'] . "' class='btn btn-primary'>编辑</a> ";
                    echo "<a href='delete-card.php?card_id=" . $row['card_id'] . "' class='btn btn-danger'>删除</a>";
                    echo "</li>";
                }
            } else {
                echo "<li class='list-group-item'>暂无卡组</li>";
            }
            ?>
        </ul>
    </div>
</body>
</html>
